package lanqiao14;
// 也难
import java.util.Arrays;
import java.util.Scanner;


public class H {
	private static int n;
	private static boolean[] isPrime;// 判断某个位置是否为质数
	private static int[] sort;// 存放某个排列
	private static int[] newSort;// 存放某个新排列
	private static int[] primes;// 存放质数位置上数
	private static int cnt = 0;// 质数的数量
	private static long sum = 0;// 逆序对的总数
	private static boolean[] num;// 判断这个数是否参加了排序
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		scan.close();
		
		//某个 index 是质数，则 isPrime[index] = true 
		isPrime = new boolean[n + 1];
		Arrays.fill(isPrime, true);
		for (int i = 4; i <= n; i++) {
			for (int j = 2; j <= (int)Math.sqrt(i); j++) {
				if (i % j == 0) {
					isPrime[i] = false;
					break;
				}
			}
		}
		
		// 质数的数量
		for (int i = 2; i <= n; i++) {
			if (isPrime[i]) {
				cnt++;
			}
		}
		
		sort = new int[n + 1];
		newSort = new int[n + 1];
		primes = new int[cnt];
		num = new boolean[n + 1];
		Arrays.fill(num, true);
		
		sortS(1);
		System.out.println(sum % 998244353);
		
		
	}
	
	// 递归找到所有的排列 sort
	private static void sortS(int index) {
		if (index == n + 1) {
			f1(newSort_(sort));
			return;
		}
		for (int j = 1; j <= n; j++) {
			if (num[j]) {
				sort[index] = j;
				num[j] = false;
				sortS(index + 1);
				num[j] = true;
			}
		}
	}
	
	// 找到某个排列 sort 的进行质数排序后的新的 newSort
	private static int[] newSort_(int[] arr) {
		int count = 0;
		for (int i = 2; i < arr.length; i++) {
			if (isPrime[i]) {
				primes[count++] = arr[i];
			}
		}
		
		sortPrimes(primes);
		count = 0;
		newSort[1] = arr[1];
		for (int i = 2; i < arr.length; i++) {
			if (isPrime[i]) {
				arr[i] = primes[count++];
			} else {
				newSort[i] = arr[i];
			}
		}
		return newSort;
	}
	
	// 判断某个排列有几个逆序对
	private static void f1(int[] arr) {
		for (int i = 2; i < arr.length; i++) {
			if (arr[i] < arr[i - 1]) {
				sum++;
			}
		}
	}
	
	// 对 primes 从小到大排序
	private static void sortPrimes(int[] arr) {
		for (int i = 1; i < arr.length; i++) {
			int num = arr[i];
			int j;
			for (j = i - 1; j >= 0; j--) {
				if (arr[j] > num) {
					arr[j + 1] = arr[j];
					continue;
				}
				break;
			}
			arr[j + 1] = num;
		}
	}
}
















